/**
 * File类的用法
 */
package edu.gzz;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author gzz
 *
 */
public class FileOperation {
	public static void main(String args[]) throws IOException {
		File f = new File("newfile.txt");
		File f2 = new File("dir");

		if (!f.exists()) {
			// f.mkdir();
			f.createNewFile();
		} else {
			System.out.println("文件已存在");
			f.delete();
		}

		FileWriter writer = new FileWriter(f);
		// 写入文件
		writer.write("This\n is\n an\n example\n");
		writer.flush();
		writer.close();

		f2.mkdir();

		System.out.println("File path:\t" + f.getPath());

		System.out.println("Is file can execute?\t" + f.canExecute());
		System.out.println("Is file can read?\t" + f.canRead());
		System.out.println("Is file can write?\t" + f.canWrite());

		// f.delete();
	}
}
